package scala.Functional

object PartialFunction {
   def main(args: Array[String]): Unit = {
      val f = partFunc("<div>", _: String, "</div")
      val html = "<table><tr><td>This is first columns</td></tr></table>"
      println(f(html))
   }

   def partFunc(pre: String, html: String, pos: String): String = {
      return pre + "\n" + html + "\n" + pos
   }

   //define partial function
   def convert1To5 = new PartialFunction[Int, String] {
      val nums = Array("one", "two", "three", "four", "five")
      def apply(i: Int) = nums(i)
      def isDefinedAt(i: Int) = (i > 0 && i <= 5)
   }

   def convert6To10 = new PartialFunction[Int, String] {
      val nums = Array("six", "seven", "eight", "nine", "ten")
      def apply(i:Int) = nums(i-6)
      def isDefinedAt(i:Int) = i>=6 && i<= 10 
   }
}